/*
 * Class representing a book of a library, inherit from media
 * @author M.T. Segarra, G. Piraux, M-A. Taupenot
 * @version 1.0.0
 */
package booksManagement;


import java.util.*;

import exceptions.*;

//not up to date yet
//import loansManagement.Loan;

import javax.persistence.*;

import org.hibernate.annotations.NaturalId;

import subscribersManagement.UtilsDate;

/**
 * Entity implementation class for Entity: Book inheritance from Media class
 */
@Entity
@DiscriminatorValue("Book")
@Table(name="books")
@NamedQuery(name="findAllBooks", query="select b from Book b")
public class Book extends Media {

	
	/*/**
   * @uml.property  name="title"
   */
	/*@Column (name="book_title")
	private String title;

	/**
	 * Getter of the property <tt>title</tt>
	 * 
	 * @return Returns the title.
	 * @uml.property name="title"
	 */
	/*public String getTitle() {
		return title;
	}

	/**
	 * Setter of the property <tt>title</tt>
	 * 
	 * @param title
	 *            The title to set.
	 * @uml.property name="title"
	 */
	/*public void setTitle(String title) {
		this.title = title;
	}*/

	/**
   * 
   */
  private static final long serialVersionUID = 1L;
	/**
   * @uml.property  name="authors"
   */
	@Transient

	@Column(name= "authors")
	private List<String> authors;

	/**
   * Getter of the property <tt>authors</tt>
   * @return       Returns the authors.
   * @uml.property  name="authors"
   */
	public List<String> getAuthors() {
		return authors;
	}

	/**
   * Setter of the property <tt>authors</tt>
   * @param authors       The authors to set.
   * @uml.property  name="authors"
   */
	public void setAuthors(List<String> authors) {
		if (authors==null)
			throw new NullPointerException("null list of authors");
		this.authors = authors;
	}

	/*/**
   * @uml.property  name="editionDate"
   */
	/*
	@Column(name="editionDate")
	private Calendar editionDate;

	/**
	 * Getter of the property <tt>editionDate</tt>
	 * 
	 * @return Returns the editionDate.
	 * @uml.property name="editionDate"
	 */
	/*public Calendar getEditionDate() {
		return editionDate;
	}

	/**
	 * Setter of the property <tt>editionDate</tt>
	 * 
	 * @param editionDate
	 *            The editionDate to set.
	 * @uml.property name="editionDate"
	 */
	/*public void setEditionDate(Calendar editionDate) {
		this.editionDate = editionDate;
	}*/

	/*/**
   * property proper to book : ISBN number
   * @uml.property  name="isbn"
   */
	/*@NaturalId
	@Column (name="isbn")
	private String isbn;

	/**
   * Getter of the property <tt>isbn</tt>
   * @return     Returns the isbn.
   * @uml.property  name="isbn"
   */
	/*public String getIsbn() {
		return isbn;
	}

	/*
	 * Two books are equal if their ISBN is the same
	 */
	@Override
	public boolean equals(Object book) {
		if (book == null)
			return false;
		Book b = (Book) book;

		if (b.isbn_isan == isbn_isan)
			return true;

		return false;
	}

	public Book(){};
	
	/**
	 * Creates a book, All parameters should be given
	 * 
	 * @param title
	 *            the title of the book
	 * @param authors
	 *            the list of the authors (names)
	 * @param editionDate
	 *            date of the edition of the book
	 * @param isbn
	 *            ISBN of the book
	 * @throws BadParametersException
	 */
	public Book(String title, List<String> authors, Calendar editionDate,
			java.lang.String isbn) throws BadParametersException {
		super(title, editionDate);
		this.setAuthors(authors);
		this.setIsbn(isbn);
	}
	
	public Book(String title, List<String> authors, Calendar editionDate,
			java.lang.String isbn, int copyAmount) throws BadParametersException {
		super(title, editionDate, copyAmount);
		this.setAuthors(authors);
		this.setIsbn(isbn);
	}

	/**
   * Setter of the property <tt>isbn</tt>
   * @param isbn       The isbn to set.
   * @uml.property  name="isbn"
   */
	public void setIsbn(String isbn) {
		if (isbn==null)
			throw new NullPointerException("null isbn");
		this.isbn_isan = isbn;
	}

	/*/**
	 * @uml.property name="loan"
	 * @uml.associationEnd inverse="book:loansManagement.Loan"
	 */
	/*
	@Transient
	private Loan loan;

	/**
	 * Getter of the property <tt>loan</tt>
	 * 
	 * @return Returns the loan.
	 * @uml.property name="loan"
	 */
	/*
	public Loan getLoan() {
		return loan;
	}

	/**
	 * Setter of the property <tt>loan</tt>
	 * 
	 * @param loan
	 *            The loan to set.
	 * @uml.property name="loan"
	 */
	/*
	public void setLoan(Loan loan) {
		this.loan = loan;
	}

	/**
	 * @return true if this book is lent
	 */
	/*
	public boolean isLent() {
		return (loan != null);
	}

	/**
	 * Makes actions to return a book No test if the return date is lower than
	 * today
	 * 
	 * @throws LentBookException
	 * @throws BadParametersException
	 */
	/*
	public void returnBook() throws LentBookException, BadParametersException {

		if (!isLent())
			throw new LentBookException("The book is not lent");

		loan.returnBook();

		this.loan = null;
	}

	/**
	 * @throws LentBookException
	 */
	/*
	public void lend(Loan loan) throws LentBookException {
		// Check if the book is available
		if (this.isLent())
			throw new LentBookException("Book already lent.");

		this.loan = loan;
	}*/
	/*
	/**
   * @uml.property  name="loan"
   * @uml.associationEnd  inverse="book:loansManagement.Loan"
   */
	@Override
	public String toString() {
		return this.title + ", " + this.isbn_isan + ", " + UtilsDate.dateToString(editionDate.getTime()) + ", number of copies : " +this.copies.size();
	}


}